package com.cyandpos.pad.refund.adapter;

import android.app.Activity;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.cyandpos.pad.R;
import com.cyandpos.pad.posdata.Coupon;
import com.cyandpos.pad.utils.CommonUtils;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ShowCouponAdapter extends RecyclerView.Adapter<ShowCouponAdapter.ViewHolder> {

    private LayoutInflater mLayoutInflater;
    private ArrayList<Coupon> mDatas;
    private Activity mContext;
    public ShowCouponAdapter(Activity context, ArrayList<Coupon> list) {
        mContext =  context;
        this.mDatas = list;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(mLayoutInflater.inflate(R.layout.list_show_coupon_item, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.mYhjmc.setText(mDatas.get(position).getCouponTypeName());
        holder.mYhjje.setText(mDatas.get(position).getAvailableAmount());
        if(!CommonUtils.isNullOrEmpty(mDatas.get(position).getValidDate())){
            holder.llDeadline.setVisibility(View.VISIBLE);
            holder.mDeadLine.setText(mDatas.get(position).getValidDate());
        }
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_yhjmc_item)
        TextView mYhjmc;
        @BindView(R.id.tv_yhjje_item)
        TextView mYhjje;
        @BindView(R.id.ll_deadLine_item)
        LinearLayout llDeadline;
        @BindView(R.id.tv_deadline)
        TextView mDeadLine;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
